package com.moxiao.yfjh.module.blind.controller.admin.memberSayHello;

import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;
import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloExcelVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloUpdateReqVO;
import com.moxiao.yfjh.module.blind.convert.memberSayHello.MemberSayhelloConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberSayHello.MemberSayhelloDO;
import com.moxiao.yfjh.module.blind.service.memberSayHello.MemberSayhelloService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "管理后台 - 相亲会员打招呼")
@RestController
@RequestMapping("/blind/member-sayhello")
@Validated
public class MemberSayhelloController {

    @Resource
    private MemberSayhelloService memberSayhelloService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲会员打招呼")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:create')")
    public CommonResult<Long> createMemberSayhello(@Valid @RequestBody MemberSayhelloCreateReqVO createReqVO) {
        return success(memberSayhelloService.createMemberSayhello(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲会员打招呼")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:update')")
    public CommonResult<Boolean> updateMemberSayhello(@Valid @RequestBody MemberSayhelloUpdateReqVO updateReqVO) {
        memberSayhelloService.updateMemberSayhello(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲会员打招呼")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:delete')")
    public CommonResult<Boolean> deleteMemberSayhello(@RequestParam("id") Long id) {
        memberSayhelloService.deleteMemberSayhello(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲会员打招呼")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:query')")
    public CommonResult<MemberSayhelloRespVO> getMemberSayhello(@RequestParam("id") Long id) {
        MemberSayhelloDO memberSayhello = memberSayhelloService.getMemberSayhello(id);
        return success(MemberSayhelloConvert.INSTANCE.convert(memberSayhello));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲会员打招呼列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:query')")
    public CommonResult<List<MemberSayhelloRespVO>> getMemberSayhelloList(@RequestParam("ids") Collection<Long> ids) {
        List<MemberSayhelloDO> list = memberSayhelloService.getMemberSayhelloList(ids);
        return success(MemberSayhelloConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲会员打招呼分页")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:query')")
    public CommonResult<PageResult<MemberSayhelloRespVO>> getMemberSayhelloPage(@Valid MemberSayhelloPageReqVO pageVO) {
        PageResult<MemberSayhelloDO> pageResult = memberSayhelloService.getMemberSayhelloPage(pageVO);
        return success(MemberSayhelloConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲会员打招呼 Excel")
    @PreAuthorize("@ss.hasPermission('blind:member-sayhello:export')")
    @OperateLog(type = EXPORT)
    public void exportMemberSayhelloExcel(@Valid MemberSayhelloExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<MemberSayhelloDO> list = memberSayhelloService.getMemberSayhelloList(exportReqVO);
        // 导出 Excel
        List<MemberSayhelloExcelVO> datas = MemberSayhelloConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲会员打招呼.xls", "数据", MemberSayhelloExcelVO.class, datas);
    }

}
